package com.li.flink.dataset

import org.apache.flink.api.scala.ExecutionEnvironment

object BatchWordCount {
  def main(args: Array[String]): Unit = {
    val environment = ExecutionEnvironment.getExecutionEnvironment
    val inputPath = "/Users/lijiacen/Downloads/test.txt"

    val text = environment.readTextFile(inputPath)

    import org.apache.flink.api.scala._
    //处理数据
    val wordCount = text.flatMap(_.split(" ")) //将每一行数据根据空格切分单词
      .map((_, 1)) // 转为tuple2形式(单词,1)
      .groupBy(0).sum(1).setParallelism(1) //并行度设置为1，将所有数据写到一个文件内，查看结果方便
    wordCount.print()
  }
}
